import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {OrderVO, OrderForm, OrderQuery} from '@/api/business/order/types';

/**
 * 查询订单列表
 * @param query
 * @returns {*}
 */

export const listOrder = (query?: OrderQuery): AxiosPromise<OrderVO[]> => {
  return request({
    url: '/business/order/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询订单详细
 * @param goodsOrderId
 */
export const getOrder = (goodsOrderId: string | number): AxiosPromise<OrderVO> => {
  return request({
    url: '/business/order/' + goodsOrderId,
    method: 'get'
  });
};

/**
 * 新增订单
 * @param data
 */
export const addOrder = (data: OrderForm) => {
  return request({
    url: '/business/order',
    method: 'post',
    data: data
  });
};

/**
 * 修改订单
 * @param data
 */
export const updateOrder = (data: OrderForm) => {
  return request({
    url: '/business/order',
    method: 'put',
    data: data
  });
};

/**
 * 删除订单
 * @param goodsOrderId
 */
export const delOrder = (goodsOrderId: string | number | Array<string | number>) => {
  return request({
    url: '/business/order/' + goodsOrderId,
    method: 'delete'
  });
};

/**
 * 派单
 * @param orderId
 */
export const dispatchApi = (params: any) => {
  return request({
    url: '/business/order/dispatch',
    method: 'put',
    params: params
  });
};

/**
 * 打手列表
 */
export const getExaminersApi = (params: any) => {
  return request({
    url: '/business/businessUser/list',
    method: 'get',
    params: params
  });
};

/**
 * 退款
 * @param orderId
 */
export const refundApi = (orderId: any) => {
  return request({
    url: '/business/order/refund',
    method: 'put',
    params: {orderId}
  });
};

export const endOrder = (orderId: any) => {
  return request({
    url: '/business/order/end',
    method: 'put',
    params: {orderId}
  });
};
export const againOrder = (orderId: any) => {
  return request({
    url: '/business/order/again',
    method: 'put',
    params: {orderId}
  });
};
